from fastapi import APIRouter, Depends, Query
from typing import Optional

from database.database import Model
from database.database_function import get_db
from api.schemas.models import ModelResponse


router = APIRouter()


@router.get("/models", summary="获取可用模型列表")
async def get_models(model_type: Optional[str] = Query(None, description="可选：chat 或 embedding"), db=Depends(get_db)):
    query = db.query(Model).filter(Model.is_active == True)
    if model_type:
        query = query.filter(Model.model_type == model_type)
    models = query.order_by(Model.model_id).all()
    return {
        "models": [
            ModelResponse(
                model_id=model.model_id,
                model_name=model.model_name,
                display_name=model.display_name,
                description=model.description or "",
                is_active=model.is_active,
                model_type=model.model_type
            )
            for model in models
        ]
    }


